home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Performance Co-Pilot 1.3
/
SGI Performance Co-Pilot 1.3.iso
/
dist
/
pcp.idb
/
usr
/
pcp
/
bin
/
cron.pmcheck.z
/
cron.pmcheck
Wrap
Text File
|
1997-04-03
|
7KB
|
322 lines
#!/bin/sh
#
# Copyright 1995, Silicon Graphics, Inc.
# ALL RIGHTS RESERVED
#
# UNPUBLISHED -- Rights reserved under the copyright laws of the United
# States. Use of a copyright notice is precautionary only and does not
# imply publication or disclosure.
#
# U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
# Use, duplication or disclosure by the Government is subject to restrictions
# as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
# in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
# in similar or successor clauses in the FAR, or the DOD or NASA FAR
# Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
# 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
#
# THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
# INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
# DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
# PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
# GRAPHICS, INC.
#
# Example administrative script to check pmlogger instances are alive,
# and restart as required.
#
# constant setup
#
tmp=/tmp/$$
status=0
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
prog=`basename $0`
# control file for pmlogger administration ... edit the entries in this
# file to reflect your local configuration
#
CONTROL=/var/pcp/config/pmlogger/control
# determine real name for localhost
LOCALHOSTNAME="localhost"
[ -x /usr/bsd/hostname ] && LOCALHOSTNAME=`/usr/bsd/hostname`
LOGDIR=${PCP_LOGDIR-/var/adm/pcplog}/$LOCALHOSTNAME
# default location
#
logfile=pmlogger.log
# option parsing
#
ECHO=false
usage="Usage: $prog [-c control] [-n]"
while getopts c:n? c
do
case $c
in
c) CONTROL="$OPTARG"
;;
n) ECHO=true
;;
?) echo "$usage"
status=1
exit
;;
esac
done
shift `expr $OPTIND - 1`
if [ $# -ne 0 ]
then
echo "$usage"
status=1
exit
fi
if [ ! -f $CONTROL ]
then
echo "$prog: Error: cannot find control file ($CONTROL)"
status=1
exit
fi
_error()
{
echo "$prog: [$CONTROL:$line]"
echo "Error: $1"
echo "... logging for host \"$host\" unchanged"
touch $tmp.err
}
_warning()
{
echo "$prog [$CONTROL:$line]"
echo "Warning: $1"
}
_get_logfile()
{
set - $args
# ignore errors, as only looking for -l
#
while getopts l: c >/dev/null 2>&1
do
case $c
in
l) logfile="$OPTARG"
;;
esac
done
}
_check_logfile()
{
if [ ! -f $logfile ]
then
echo "Cannot find pmlogger output file at \"$logfile\""
else
echo "Contents of pmlogger output file \"$logfile\" ..."
cat $logfile
fi
}
_check_logger()
{
# wait until pmlogger process starts, or exits
#
delay=5
[ ! -z "$PMCD_CONNECT_TIMEOUT" ] && delay=$PMCD_CONNECT_TIMEOUT
x=5
[ ! -z "$PMCD_REQUEST_TIMEOUT" ] && x=$PMCD_REQUEST_TIMEOUT
# wait for maximum time of a connection and 20 requests
#
delay=`expr $delay + 20 \* $x`
i=0
while [ $i -lt $delay ]
do
echo ".\c"
if echo "connect $1" | pmlc >$tmp.out 2>&1
then
if grep "Unable to connect" $tmp.out >/dev/null
then
:
else
sleep 5
echo " done"
return 0
fi
fi
if ps -ef | grep pmlogger | nawk '
BEGIN { sts=0 }
$2 == '$1' { sts=1; exit sts }
END { exit sts }'
then
echo " process exited!"
_check_logfile
return 1
fi
sleep 5
i=`expr $i + 5`
done
echo " timed out waiting!"
sed -e 's/^/ /' $tmp.out
_check_logfile
return 1
}
# note on control file format version
# 1.0 was shipped as part of PCPWEB beta, and did not include the
# socks field [this is the default for backwards compatibility]
# 1.0 is the first production release, and the version is set in
# the control file with a $version=1.1 line (see below)
#
if /sbin/chkconfig pmlogger
then
echo $LOGDIR >$tmp.dir
else
echo >$tmp.dir
fi
rm -f $tmp.err
line=0
version=1.0
cat $CONTROL \
| sed -e "s/LOCALHOSTNAME/$LOCALHOSTNAME/g" \
| while read host primary socks dir args
do
line=`expr $line + 1`
case "$host"
in
\#*|'') # comment or empty
continue
;;
\$*) # in-line shell command
cmd=`echo "$host $primary $socks $dir $args" | sed -e 's/^\\$//'`
eval $cmd
continue
;;
esac
if [ "$version" = "1.0" ]
then
args="$dir $args"
dir="$socks"
socks=n
fi
# make sure output directory exists
#
if [ ! -d $dir ]
then
mkdir -p $dir
if [ ! -d $dir ]
then
_error "cannot create directory ($dir) for PCP archive files"
else
_warning "creating directory ($dir) for PCP archive files"
fi
fi
[ ! -d $dir ] && continue
# check for directory duplicate entries
#
if grep $dir $tmp.dir >/dev/null
then
if [ "X$primary" != Xy ]
then
_error "Cannot start more than one pmlogger instance for archive directory \"$dir\""
continue
fi
else
echo "$dir" >>$tmp.dir
fi
cd $dir
$ECHO && echo "+ cd $dir"
if [ "X$primary" = Xy ]
then
if [ "X$host" != "X$LOCALHOSTNAME" ]
then
_error "\"primary\" only allowed for $LOCALHOSTNAME (localhost, not $host)"
continue
fi
if /sbin/chkconfig pmlogger
then
:
else
_error "primary logging disabled via chkconfig for $host"
continue
fi
pid=`ps -ef \
| sed -n \
-e '/grep/d' \
-e 's/$/ /' \
-e '/\/usr\/pcp\/bin\/pmlogger .*-P /p' \
| nawk '{print $2}'`
else
pid=`ps -ef \
| sed -n \
-e '/grep/d' \
-e 's/$/ /' \
-e "/\/usr\/pcp\/bin\/pmlogger .*-h *$host /p" \
| nawk '{print $2}'`
fi
if [ "X$pid" = X ]
then
rm -f Latest
if [ "X$primary" = Xy ]
then
args="-P $args"
iam=" primary"
# clean up port-map, just in case
#
PM_LOG_PORT_DIR=/var/tmp/pmlogger
rm -f $PM_LOG_PORT_DIR/primary $PM_LOG_PORT_DIR/vcr
else
args="-h $host $args"
iam=""
fi
# each new log started is named yymmdd.hh.mm
#
LOGNAME=`date "+%y%m%d.%H.%M"`
echo "Restarting$iam pmlogger for host \"$host\" ...\c"
sock_me=''
[ "$socks" = y ] && sock_me='pmsocks '
_get_logfile
[ -f $logfile ] && mv -f $logfile $logfile.prior
if $ECHO
then
echo
echo "+ ${sock_me}/usr/pcp/bin/pmlogger $args $LOGNAME"
continue
else
${sock_me}/usr/pcp/bin/pmlogger $args $LOGNAME >$tmp.out 2>&1 &
pid=$!
fi
# wait for pmlogger to get started, and check on its health
_check_logger $pid
# the archive folio Latest is for the most recent archive in
# this directory
#
[ -f $LOGNAME.0 ] && /usr/pcp/bin/mkaf $LOGNAME.0 >Latest
fi
done
[ -f $tmp.err ] && status=1
exit